﻿﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<title>:: Swift - Hospital Admin ::</title>
<link href="assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link rel="icon" href="favicon.ico" type="image/x-icon">

    <script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://lib.baomitu.com/layui/2.6.5/layui.min.js"></script>
    <link href="https://lib.baomitu.com/layui/2.6.5/css/layui.min.css" rel="stylesheet">

<!-- Custom Css -->
<link href="assets/css/main.css" rel="stylesheet">
<link href="assets/css/login.css" rel="stylesheet">

<!-- Swift Themes. You can choose a theme from css/themes instead of get all themes -->
<link href="assets/css/themes/all-themes.css" rel="stylesheet" />
</head>
<body class="theme-cyan login-page authentication">
<div class="container">
    <div class="card-top"></div>
    <div class="card">
        <h1 class="title">注册 <span class="msg"></span></h1>
        <div class="col-md-12">
            <form id="sign_up" class="col-xs-12" method="POST">            
            <div class="input-group">
                <span class="input-group-addon">
                    <i class="zmdi zmdi-account"></i>
                </span>
                <div class="form-line">
                    <input type="text" class="form-control" id="uname" placeholder="请输入 您的姓名"  required="" autofocus>
                </div>
            </div>
<script>
  var namee= /^[\u4E00-\u9FA5]{1,6}$/;
  $("#uname").blur(function () {
    var  uname= $("#uname").val();
    if(!namee.test(uname)){
        layer.open({
            title:'错误提示'
            ,content:'姓名不合法，或姓名为空，请重新输入'
            ,icon:2
        });
        $("#uname").val("");
        return false;}
  })
</script>
            <div class="input-group">
                <span class="input-group-addon">
                    <i class="zmdi zmdi-account"></i>
                </span>
                <div class="form-line">
                    <input type="text" id="idcard" class="form-control" name="email" placeholder="身份证号" required="">
                </div>
            </div>

                <div class="input-group">
                <span class="input-group-addon">
                    <i class="zmdi zmdi-account"></i>
                </span>
                    <div class="form-line" >
                        <input type="text" id="phone" class="form-control" style="width: 185px;float: left" placeholder="手机号">
                    </div>
                </div>

                <div class="input-group">
                <span class="input-group-addon">
                    <i class="zmdi zmdi-account"></i>
                </span>
                    <div class="form-line">
                        <input type="text" id="code" class="form-control" style="width: 185px;float: left"  placeholder="请输入验证码" required="">
                        <input type="button" class="layui-btn layui-btn-sm layui-btn-normal" id="verify_but" style="width: 85px;float: right" value="发送验证码">
                    </div>
                </div>

            <div class="input-group">
                <span class="input-group-addon">
                    <i class="zmdi zmdi-lock"></i>
                </span>
                <div class="form-line">
                    <input type="password" id="psdone" class="form-control" name="password" minlength="6" placeholder="请输入密码" required="">
                </div>
            </div>
            <div class="input-group">
                <span class="input-group-addon">
                    <i class="zmdi zmdi-lock"></i>
                </span>
                <div class="form-line">
                    <input type="password" id="psdtwo" class="form-control" name="confirm" minlength="6" placeholder="确认您的密码" required="">
                </div>
            </div>
            <div class="form-group">
                <input type="checkbox" name="terms" id="terms" class="filled-in chk-col-pink">
                <label for="terms">阅读并同意 <a href="javascript:void(0);">使用条款</a>.</label>
            </div>
            <div class="text-center">
                <a href="#" id="register" class="layui-btn layui-btn-sm">注册</a>
            </div>
            <div class="m-t-10 m-b--5 align-center">
                <a href="sign-in.html">您 已 有 账 号?</a>
            </div>
        </form>
        </div>
    </div>  
</div>
<div class="theme-bg"></div>
<!-- Jquery Core Js -->
<script src="assets/bundles/libscripts.bundle.js"></script> <!-- Lib Scripts Plugin Js -->
<script src="assets/bundles/vendorscripts.bundle.js"></script> <!-- Lib Scripts Plugin Js -->
<script src="assets/bundles/mainscripts.bundle.js"></script><!-- Custom Js -->

</body>
</html>
<script>
    var  sessionCode;
$("#verify_but").click(function () {
    var phone=$("#phone").val();
    var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
  if(phone==""){
      layer.open({
          title:'错误提示'
          ,content:'请输入手机号'
          ,icon:2
      });
return false;
  }else  if(!reg_tel.test(phone)){
      layer.open({
          title:'错误提示'
          ,content:'手机号格式不正确,请重新输入!'
          ,icon:2
      });
      return false;
  }else {
      $.get("/register/registerCode",{phone:phone},function (data) {
          if(data!=null){
              timer();
              sessionCode=data;
          }
      })
  }
})

 var sexx;

$("#idcard").blur(function () {
    var idcard=$("#idcard").val();
       getCheckId(idcard);
     var checkId=getCheckId(idcard);
         layer.msg(checkId);
if(checkId!=='验证通过!'){
    $("#idcard").val("");
    return false
}else {
    if(idcard.length==18){
        if(idcard.substr(16,1)%2==1){
            sexx="男";
            console.log(sexx)
        }else{
            sexx="女";
            console.log(sexx)
        }
    }else if(idcard.length==15){
        if(idcard.substr(14,1)%2==1){
            sexx="男";
            console.log(sexx)
        }else{
            sexx="女";
            console.log(sexx)
        }
    }
}
})
$("#register").click(function () {
    var uname = $("#uname").val();//姓名
    var idcard = $("#idcard").val();//身份证号
    var phone = $("#phone").val();//手机号
    var code = $("#code").val();//验证码
    var psdone = $("#psdone").val();//密码1
    var psdtwo = $("#psdtwo").val();//密码2
    var birthday= getBirthday(idcard);//出生日期
    var terms=document.getElementById("terms")
//性别
if(uname=="" || idcard=="" || phone=="" ||code=="" || psdone=="" || psdtwo=="" ){
    layer.open({
        title:'错误提示'
        ,content:'请先完善信息,在注册!!'
        ,icon:2
    });
    return false;
} else if(!terms.checked){
    layer.open({
        title:'错误提示'
        ,content:'请先勾选同意使用条款!!'
        ,icon:2
    });
    $("#terms").css("border-color","red");
    return false;
}else{
if(psdone!==psdtwo){
    layer.open({
        title:'错误提示'
        ,content:'两次密码输入不一致，请先确认密码!'
        ,icon:2
    });
    return false;
}else {
    if(sessionCode==code){
    $.get("/register/phone_sole",{phone:phone},function (data) {
   if(data==true){
       $.ajax({
           type:"get",
           url:"/register/user_add",
           data:{
               uname:uname ,
               idcard:idcard,
               phone:phone ,
               birthday:birthday,
               sex:sexx,
               password:psdone
           },
           dataType:"json",
           success:function (data) {
           if (data> 0){
    layer.confirm("注册成功，您的登录账号为<span style='color: red;font-size: 20px'>"+data+"</span><br/>"+"点击确认后，将会跳转到登录页面"
        ,function () {
        window.location.href="http://localhost:8080/ManagementEnd/sign-in.html"
    })
           }else {
               layer.open({
                   title:'失败提示'
                   ,content:'注册失败请重试!'
                   ,icon:2
               });
           }
           }})
   }else {
       layer.open({
           title:'错误提示'
           ,content:'该手机号已注册,请重新输入!'
           ,icon:2
       });
       return false;
   }
    })
}else {
        layer.open({
            title:'错误提示'
            ,content:'验证码错误,请重新输入!'
            ,icon:2
        });
        return false;


    }
}}
})

</script>





<script>
    //   var countdown = 60;
    //   function settime(val) {
    //     var stime = setTimeout(function () {
    //         settime(val)
    //     }, 1000)
    //     if (countdown == 0) {
    //         val.removeAttribute("disabled");
    //         val.value = "发送验证码";
    //         countdown = 60;
    //         clearTimeout(stime);
    //     } else {
    //         val.setAttribute("disabled", true);
    //         val.value = "重新发送("+countdown+")";
    //         countdown--;
    //     }
    // }
    var wait = 60;
    //倒计时
    function timer() {
        if(wait == 0){
            $("#verify_but").val("获取验证码");
            $("#verify_but").removeAttr("disabled");
            $("#verify_but").css("border-color","1e9fff").css("background", "#ffffff").css("cursor", "pointer");
            wait = 60;
        }else{
            $("#verify_but").attr("disabled","true");
            $("#verify_but").css("border-color","fbfbfb").css("background", "#ccc").css("cursor", "not-allowed");
            $("#verify_but").val(wait + "秒后重发");
            wait--;
            setTimeout(function() {timer()}, 1000);
        }
    }
</script>
<script>

//截取身份证号获得出生年月日
function getBirthday(idno) {
var birthday="";
if (idno.length==18){
  var  year= idno.substr(6,4);
    var  month= idno.substr(10,2);
    var  day= idno.substr(12,2);
    birthday=year+"-"+month+"-"+day;
    return birthday;
}else if(idno.length==15){
    var  year="19"+ idno.substr(6,2);
    var  month= idno.substr(8,2);
    var  day= idno.substr(10,2);
    birthday=year+"-"+month+"-"+day;
    return birthday;
}
}
    //身份证效验正则表达式
    function getCheckId(idcard) {
        var Errors = new Array("验证通过!", "身份证号码位数不对!", "身份证号码出生日期超出范围或含有非法字符!", "身份证号码校验错误!", "身份证地区非法!");
        var area = {
            11: "北京",
            12: "天津",
            13: "河北",
            14: "山西",
            15: "内蒙古",
            21: "辽宁",
            22: "吉林",
            23: "黑龙江",
            31: "上海",
            32: "江苏",
            33: "浙江",
            34: "安徽",
            35: "福建",
            36: "江西",
            37: "山东",
            41: "河南",
            42: "湖北",
            43: "湖南",
            44: "广东",
            45: "广西",
            46: "海南",
            50: "重庆",
            51: "四川",
            52: "贵州",
            53: "云南",
            54: "西藏",
            61: "陕西",
            62: "甘肃",
            63: "青海",
            64: "宁夏",
            65: "新疆",
            71: "台湾",
            81: "香港",
            82: "澳门",
            91: "国外"
        }
        var retflag = false;
        var idcard, Y, JYM;
        var S, M;
        var idcard_array = new Array();
        idcard_array = idcard.split("");
        //地区检验
        if (area[parseInt(idcard.substr(0, 2))] == null) return Errors[4];
        //身份号码位数及格式检验
        switch (idcard.length) {
            case 15:
                if ((parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0 || ((parseInt(idcard.substr(6, 2)) + 1900) % 100 == 0 && (parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0)) {
                    ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/; //测试出生日期的合法性
                } else {
                    ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/; //测试出生日期的合法性
                }

                if (ereg.test(idcard)) {

                    return Errors[0];
                }
                else {
                    return Errors[2];
                }
                break;
            case 18:
                if (parseInt(idcard.substr(6, 4)) % 4 == 0 || (parseInt(idcard.substr(6, 4)) % 100 == 0 && parseInt(idcard.substr(6, 4)) % 4 == 0)) {
                    ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/; //闰年出生日期的合法性正则表达式
                } else {
                    ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/; //平年出生日期的合法性正则表达式
                }
                if (ereg.test(idcard)) { //测试出生日期的合法性
                    //计算校验位
                    S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 + parseInt(idcard_array[7]) * 1 + parseInt(idcard_array[8]) * 6 + parseInt(idcard_array[9]) * 3;
                    Y = S % 11;
                    M = "F";
                    JYM = "10X98765432";
                    M = JYM.substr(Y, 1); //判断校验位
                    if (M == idcard_array[17]) return Errors[0]; //检测ID的校验位
                    else return Errors[3];
                } else return Errors[2];
                break;
            default:
                return Errors[1];
                break;
        }
    };
</script>